/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import React from 'react';
import type {PropsWithChildren} from 'react';
import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  TouchableOpacity,
  useColorScheme,
  View,
} from 'react-native';
import forge from 'node-forge';

import { RNToNativeEventMoudle } from '@shared/react-native-gizwits-sdk'
import { requestPermission , checkPermission } from 'react-native-location'

import {
  Colors,
  DebugInstructions,
  Header,
  LearnMoreLinks,
  ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';

/*
type SectionProps = PropsWithChildren<{
  title: string;
}>;

function Section({children, title}: SectionProps): React.JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';
  return (
    <View style={styles.sectionContainer}>
      <Text
        style={[
          styles.sectionTitle,
          {
            color: isDarkMode ? Colors.white : Colors.black,
          },
        ]}>
        {title}
      </Text>
      <Text
        style={[
          styles.sectionDescription,
          {
            color: isDarkMode ? Colors.light : Colors.dark,
          },
        ]}>
        {children}
      </Text>
    </View>
  );
}

function clickAction(){
  console.log("qqww")
  var iv = '167221095134';

  var cipher = forge.cipher.createCipher('AES-GCM', '528403f9218d4cc2aa4f02b2947edd9e'); // 生成AES-GCM模式的cipher对象 并传入密钥
  cipher.start({
    iv: iv,
  });
  cipher.finish();
  var encrypted = cipher.output;
  var tag = cipher.mode.tag;
  console.log(`forge is `,forge)
}
*/

function App(): React.JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  const createGizWifiSDKInstance = async () => {

    const whenInUsePermission = await checkPermission({ ios :"whenInUse" });
    const alwaysPermission = await checkPermission({ ios : "always" });

    if(!whenInUsePermission && !alwaysPermission){
      console.log("地理位置权限未申请");
      requestPermission({ios : "whenInUse"})
      return
    }
    console.log("地理位置权限已申请");
    RNToNativeEventMoudle.open()
  }

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <View style={styles.containerView}>
        <Text>
          Hello World
        </Text>
        <TouchableOpacity onPress={createGizWifiSDKInstance} style={styles.btn}>
          <Text>点击创建GizWifiSDK的Instance</Text>
        </TouchableOpacity>
      </View>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
  },
  highlight: {
    fontWeight: '700',
  },
  containerView : {
    width:'100%',
    height:'100%',
    justifyContent : 'center',
    alignItems : 'center'
  },
  btn : {
    height : 50,
    backgroundColor:'red',
    justifyContent : 'center',
    paddingHorizontal : 10,
    marginTop : 20
  }
});

export default App;
